#include "qwtthermohost.h"

#include "../../libs/shared/qhostfactory.h"
#include "../../libs/shared/qpropertyfactory.h"
#include "../../libs/shared/qcommonstruct.h"
#include "../../libs/shared/property/qabstractproperty.h"

QColorGroupProgrety::QColorGroupProgrety(QAbstractProperty *parent):
    QColorProperty(parent)
{
    set_property("type","Color_Group");
}

QString QColorGroupProgrety::get_value_text()
{
    QGradient g=get_value().value<QGradient>();
    return QString("Color[%1]").arg(g.stops().size());
}

QString QColorGroupProgrety::get_property_name()
{
    return "Color_Group";
}

QwtThermoHost::QwtThermoHost(QAbstractHost *parent):
    QwtAbstractScaleHost(parent)
{
}

void QwtThermoHost::init_property()
{
    QwtAbstractScaleHost::init_property();

    QAbstractProperty* pro;

    pro=QPropertyFactory::create_property("Float");
    if(pro!=NULL)
    {
        pro->set_property("name","value");
        pro->set_attribute("show_name",tr("Value"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        m_object->setProperty("value",0.0);
        insert_property(pro,2);
    }

    pro=QPropertyFactory::create_property("Enum");
    if(pro!=NULL)
    {
        pro->set_property("name","orientation");
        pro->set_attribute("show_name",tr("Orientation"));
        pro->set_attribute("group","Attributes");

        ComboItems   items;
        tagComboItem item;

        item.m_text="Horizontal";
        item.m_value=Qt::Horizontal;
        items.append(item);

        item.m_text="Vertical";
        item.m_value=Qt::Vertical;
        items.append(item);

        pro->set_attribute("items",QVariant::fromValue<ComboItems>(items));
        pro->set_attribute(ATTR_CAN_SAME,true);
        m_object->setProperty("orientation",Qt::Horizontal);
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Enum");
    if(pro!=NULL)
    {
        pro->set_property("name","scalePosition");
        pro->set_attribute("show_name",tr("Scale Position"));
        pro->set_attribute("group","Attributes");

        ComboItems   items;
        tagComboItem item;

        item.m_text="No Scale";
        item.m_value=QwtThermo::NoScale;
        items.append(item);

        item.m_text="Leading Scale";
        item.m_value=QwtThermo::LeadingScale;
        items.append(item);

        item.m_text="Trailing Scale";
        item.m_value=QwtThermo::TrailingScale;
        items.append(item);

        pro->set_attribute("items",QVariant::fromValue<ComboItems>(items));
        pro->set_attribute(ATTR_CAN_SAME,true);
        m_object->setProperty("scalePosition",QwtThermo::TrailingScale);
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Enum");
    if(pro!=NULL)
    {
        pro->set_property("name","originMode");
        pro->set_attribute("show_name",tr("Origin Mode"));
        pro->set_attribute("group","Attributes");

        ComboItems   items;
        tagComboItem item;

        item.m_text="Origin Minimum";
        item.m_value=QwtThermo::OriginMinimum;
        items.append(item);

        item.m_text="Origin Maximum";
        item.m_value=QwtThermo::OriginMaximum;
        items.append(item);

        item.m_text="Origin Custom";
        item.m_value=QwtThermo::OriginCustom;
        items.append(item);

        pro->set_attribute("items",QVariant::fromValue<ComboItems>(items));
        pro->set_attribute(ATTR_CAN_SAME,true);
        m_object->setProperty("originMode",QwtThermo::OriginMinimum);
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Float");
    if(pro!=NULL)
    {
        pro->set_property("name","origin");
        pro->set_attribute("show_name",tr("Origin"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        m_object->setProperty("origin",0.0);
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Number");
    if(pro!=NULL)
    {
        pro->set_property("name","spacing");
        pro->set_attribute("show_name",tr("Spacing"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        m_object->setProperty("spacing",3);
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Number");
    if(pro!=NULL)
    {
        pro->set_property("name","borderWidth");
        pro->set_attribute("show_name",tr("Border Width"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        m_object->setProperty("borderWidth",2);
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Number");
    if(pro!=NULL)
    {
        pro->set_property("name","pipeWidth");
        pro->set_attribute("show_name",tr("Pipe Width"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        m_object->setProperty("pipeWidth",10);
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Color");
    if(pro!=NULL)
    {
        pro->set_property("name","border_color");
        pro->set_attribute("show_name",tr("Border Color"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        pro->setProperty("color",true);

        QLinearGradient g;
        g.setColorAt(0,QColor(128,128,128));

        m_object->setProperty("border_color",QVariant::fromValue<QGradient>(g));
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Color");
    if(pro!=NULL)
    {
        pro->set_property("name","background_color");
        pro->set_attribute("show_name",tr("Background Color"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Color");
    if(pro!=NULL)
    {
        pro->set_property("name","text_color");
        pro->set_attribute("show_name",tr("Text Color"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        pro->setProperty("color",true);
        insert_property(pro);
    }


    pro=QPropertyFactory::create_property("Color_Group");
    if(pro!=NULL)
    {
        pro->set_property("name","color_group");
        pro->set_attribute("show_name",tr("Value Color"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);

        QRadialGradient g;
        g.setColorAt(0,QColor(0,0,0));
        g.setColorAt(0.2,QColor(192,0,0));
        g.setColorAt(1,QColor(255,0,0));
        m_object->setProperty("color_group",QVariant::fromValue<QGradient>(g));
        insert_property(pro);
    }


    set_property_value("geometry",QRect(0,0,400,60));
}

QString QwtThermoHost::get_show_name()
{
    return tr("QWT Thermo");
}

QString QwtThermoHost::get_show_group()
{
    return tr("QWT Widgets");
}

QString QwtThermoHost::get_show_icon()
{
    return ":/images/progress_bar.png";
}

void QwtThermoHost::create_object()
{
    m_object=new QwtThermo;
    m_object->setObjectName("thermo");
}

qRegisterHost("qwt.thermo",QwtThermoHost,6020)
qRegisterProperty(QColorGroupProgrety)
